# -*- encoding=utf8 -*-
import time
from apicore.PocoApi import PocoApi
from base_page.phone_home.Phone_Home import Phone_Home

""" 一键安装 """
class OneClickInstallation(PocoApi):
    def __init__(self):
        super().__init__()
        self.phone_home=Phone_Home()
    # 进入一键安装
    def enter_page(self):
        time.sleep(2)
        self.phone_home.one_click_installation()
    def everyone_click_installation(self,apptext):
        self.enter_page()
        for i in apptext:
            self.phone_home.poco_click(text=i)
            time.sleep(2)
    def recommentslipeup(self):##一键安装控件上滑控件框单独方法
        view_group=self.poco("android.widget.FrameLayout").offspring("com.unicom.cloudphone:id/bottomPopupContainer").child("android.view.ViewGroup")
        view_group.click()
        if view_group.exists():
            bounds = view_group.get_bounds()
            x1,y1=bounds[0],bounds[1]
            x2,y2=bounds[2],bounds[3]
        #     x1, y1 = bounds[0]  # 左上角坐标
        #     x2, y2 = bounds[1]  # 右下角坐标
            print(x1,y1,x2,y2)
            end_point = [x1 + (x2 - x1) / 2, y2 - (y2 - y1) * 0.2]  # 控件底部的80%位置
            start_point = [x1 + (x2 - x1) / 2, y1 + (y2 - y1) * 0.2]    # 控件顶部的20%位置
        # 执行向下滑动操作
            self.poco.swipe(start_point, end_point, duration=1.0)
            time.sleep(2)
        else:
            print("123")
    def enter_OneClickInstallation(self):
        time.sleep(3)
        # self.poco(name="com.unicom.cloudphone:id/bt_install", text="一键安装").click()
        self.poco_click_name_test("com.unicom.cloudphone:id/bt_install",text="一键安装")
        time.sleep(5)

